<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <button id="btn">计算两个随机数的乘积</button>
    <script>
      let worker;
      const btn = document.getElementById("btn");
      btn.addEventListener("click", calculate);

      function calculate() {
        worker.postMessage([
          Math.floor(Math.random() * 10000) + 1,
          Math.floor(Math.random() * 10000) + 1,
        ]);
      }

      if (typeof Worker !== "undefined") {
        worker = new Worker("./worker.js");

        worker.onmessage = (e) => {
          console.log("结果", e.data);
        };
      }
    </script>
  </body>
</html>
